home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / HQX 1.0 / example / hqx.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-05  |  4.0 KB  |  89 lines  |  [TEXT/MPS ]

  1.  
  2. #ifndef __HQX__
  3. #define __HQX__
  4.  
  5. /* file hqx.h 
  6.     BinHex decoder/encoder routines, definitions.
  7.     Copyright (c) 1995, 1996, 1997 by John Montbriand.  All Rights Reserved.
  8.     Permission hereby granted for public use.
  9.         Distribute freely in areas where the laws of copyright apply.
  10.     USE AT YOUR OWN RISK.
  11.     DO NOT DISTRIBUTE MODIFIED COPIES.
  12.     Comments/questions/postcards* to the author at the address:
  13.       John Montbriand
  14.       P.O. Box. 1133
  15.       Saskatoon Saskatchewan Canada
  16.       S7K 3N2
  17.     or by email at:
  18.       tinyjohn@sk.sympatico.ca
  19.     *if you mail a postcard, then I will provide you with technical support
  20.     regarding questions you may have about this file.
  21. */
  22.  
  23. /* routines for encoding or decoding binhex files.  These routines are designed
  24. for use with any data source/sink.  They are re-entrant so they can be used
  25. in several threads simultaneously. System 6 on up...  Can handle any file
  26. size.  Uses a chained read/write algorithm so memory requirements are low.  */
  27.  
  28. #include <Types.h>
  29. #include <Files.h>
  30.  
  31. /* BINHEX ENCODER -- encode a macintosh file in binhex format */
  32. /*    output is sent to a user-defined output sink. */
  33.  
  34. /* HQXSink defines a function that will receive data produced by
  35.     the HQXEncode routine.  refcon is available for your application's
  36.     use and is the same refcon value passed to HQXEncode.  returning
  37.     any error code other than noErr will abort HQXEncode.  HQXEncode
  38.     implements a buffering scheme of its own, so there is no need for
  39.     your sink function to be concerned about buffering data. */
  40. typedef OSErr (*HQXSink)(void* buffer, long count, long refcon);
  41.  
  42. /* HQXEncode reads the indicated macintosh file and outputs the binhex
  43.     equivalent to the sink.  If the HQXSink returns a non-zero result code,
  44.     then execution stops and HQXEncode will return the result.  refcon
  45.     is a value passed to the sink function.  */
  46. OSErr HQXEncode(StringPtr name, short vol, long dir, HQXSink dst, long refcon);
  47.  
  48.  
  49.  
  50. /* BINHEX DECODER -- decode binhex input extracted from a user */
  51. /* defined input source.   Only Binhex characters delimited by colons */
  52. /* are converted and multiple binhex data sections are allowed. */
  53. /* For example,  the data: */
  54. /*       :"@KaH#jS!:     ...some garbage characters...  :&4&@&40: */
  55. /* is processed the same as the binhex sequence:*/
  56. /*       :"@KaH#jS!&4&@&40:    */
  57.  
  58.  
  59. /* HQXSource defines a function providing a data source for the HQXDecode
  60.     routine.  Your function should attempt to read *count bytes to the
  61.     buffer.  Before returning, your function should set *count to the
  62.     actual number of bytes read into the buffer.  If count is zero, or the
  63.     source function returns some result other than eofErr, HQXDecode
  64.     aborts processing.  HQXDecode implements its own buffering scheme
  65.     so your source function need not be concerned about buffering.  */
  66. typedef OSErr (*HQXSource)(void* buffer, long *count, long refcon);
  67.  
  68. /* HQXNameFilter is an optional routine allowing your application oportunity
  69.     to modify the file name and location of the macintosh file being decoded.
  70.     If your filter function returns a non-zero result code, HQXDecode stops
  71.     processing data from the source and returns the result code.  when
  72.     HQXNameFilter is called, name is the name of the file and *vol and
  73.     *dir will be zero.  Your routine can modify any or all of these parameters
  74.     to specify a different output file.  */
  75. typedef OSErr (*HQXNameFilter)(StringPtr name, short *vol, long *dir, long refcon);
  76.  
  77. /* HQXDecode decodes a binhex file using data from the source function.
  78.     fname, if not NULL, is called once the file name has been extracted from
  79.     the binhex data so you can change where the file is saved.  if can_replace
  80.     is true then decoded files will replace files with the same name.  refcon
  81.     is an application-specific parameter passed to both the name filter function
  82.     and the source function.  if header_search is true, the routine does a
  83.     search for the string "(This file must be converted with BinHex 4.0)"
  84.     before beginning decoding binhex data.  */
  85. OSErr HQXDecode(HQXSource src, HQXNameFilter fname, Boolean can_replace, 
  86.     Boolean header_search, long refcon);
  87.  
  88. #endif
  89.